﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DropNet.Models;
using umbraco.IO;

namespace TheOutfield.UmbExt.UniversalMediaPicker.Providers.Dropbox
{
    public static class DropboxExtensions
    {
        public static MediaItem ToMediaItem(this MetaData md)
        {
            var mi = new MediaItem
            {
                Id = md.Path,
                Title = md.Name,
                Icon = md.Is_Dir ? UmbracoIcons.FolderOpen : "dropbox/16x16/"+ md.Icon +".gif",
                HasChildren = md.Is_Dir,
                PreviewImageUrl = md.Is_Dir ? "" : IOHelper.ResolveUrl(SystemDirectories.Umbraco + "/images/umbraco/dropbox/48x48/" + md.Icon + ".gif"),
                Selectable = !md.Is_Dir
            };

            mi.MetaData.Add("Modified", md.Modified.ToShortDateString());
            mi.MetaData.Add("Extension", md.Extension);
            mi.MetaData.Add("Size", md.Size);

            return mi;
        }
    }
}